﻿using CQIE.JonJack.SplLibraryService._IAdmainService;
using CQIE.JonJack.SplLibraryService._IReaderService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CQIE.JonJack.SplLibraryManagementSystem.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdmainController : ControllerBase
    {
        private readonly IAdmainService _admainService;

        public AdmainController(IAdmainService admainService)
        {
            _admainService = admainService;
        }

        [HttpGet]
        [Authorize]
        public ActionResult getAllApplicationList()
        {
            return Ok(_admainService.getAllApplicationList());
        }

        [HttpGet]
        [Authorize]
        public ActionResult getReader()
        {
            return Ok(_admainService.getReader());
        }

        [HttpGet]
        [Authorize]
        public ActionResult Audit(string uid,string ac)
        {
            if(ac=="1")
            {
                _admainService.Audit(uid, true);
            }
            else
            {
                _admainService.Audit(uid, false);
            }

            return Ok();
        }

        [HttpGet]
        [Authorize]
        public ActionResult ReaderManage(string uid, string ac)
        {
            if (ac == "true")
            {
                _admainService.ReaderManage(uid, true);
            }
            else
            {
                _admainService.ReaderManage(uid, false);
            }

            return Ok();
        }
    }
}
